//
//  NetWorkingCart.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/28.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "NetWorkingCart.h"

@implementation NetWorkingCart

//加入购物车
+(void)addToCart:(NSInteger)productId skuId:(NSInteger)skuId withSuccessBlock:(void(^)(id responseObj))successBlock{
    NSString *urlStr = [NSString stringWithFormat:@"%@/%ld/%ld",ProductCart,(long)skuId,(long)productId];
    NSDictionary *params = @{@"number":@(1),@"op":@"add"};
    [NetWorkTool requestTokenPostWithUrl:urlStr WithParams:params withSuccessBlock:^(id  _Nonnull responseObj) {
        successBlock(responseObj);
    } withFailedBlock:^(NSString * _Nonnull errorStr) {
        [[XNProgressHUD shared] showErrorWithTitle:errorStr];
    }];
}

//数量减少
+(void)cartGoosLess:(NSInteger)productId skuId:(NSInteger)skuId withSuccessBlock:(void(^)(id responseObj))successBlock{
    NSString *urlStr = [NSString stringWithFormat:@"%@/%ld/%ld",ProductCart,(long)skuId,(long)productId];
    NSDictionary *params = @{@"op":@"minus"};
    [NetWorkTool requestTokenPostWithUrl:urlStr WithParams:params withSuccessBlock:^(id  _Nonnull responseObj) {
        successBlock(responseObj);
    } withFailedBlock:^(NSString * _Nonnull errorStr) {
        [[XNProgressHUD shared] showErrorWithTitle:errorStr];
    }];
}

//数量增加
+(void)cartGoosAdd:(NSInteger)productId skuId:(NSInteger)skuId withSuccessBlock:(void(^)(id responseObj))successBlock{
    NSString *urlStr = [NSString stringWithFormat:@"%@/%ld/%ld",ProductCart,(long)skuId,(long)productId];
    NSDictionary *params = @{@"op":@"plus"};
    [NetWorkTool requestTokenPostWithUrl:urlStr WithParams:params withSuccessBlock:^(id  _Nonnull responseObj) {
        successBlock(responseObj);
    } withFailedBlock:^(NSString * _Nonnull errorStr) {
        [[XNProgressHUD shared] showErrorWithTitle:errorStr];
    }];
}

//商品购物车列表
+(void)getCartListWithSuccessBlock:(void(^)(id responseObj))successBlock{
    [NetWorkTool requestTokenGetWithUrl:ProductCartList withSuccessBlock:^(id  _Nonnull responseObj) {
        successBlock(responseObj);
    } withFailedBlock:^(NSString * _Nonnull errorStr) {
        [[XNProgressHUD shared] showErrorWithTitle:errorStr];
    }];
}

//购物车  删除
+(void)deleteCartListWithIds:(NSArray *)ids withSuccessBlock:(void(^)(id responseObj))successBlock{
    NSDictionary *params = @{@"Ids":[ids componentsJoinedByString:@","]};
    
    [NetWorkTool requestTokenPostWithUrl:ProductCartDelete WithParams:params withSuccessBlock:^(id  _Nonnull responseObj) {
        successBlock(responseObj);
    } withFailedBlock:^(NSString * _Nonnull errorStr) {
        [[XNProgressHUD shared] showErrorWithTitle:errorStr];
    }];
}





@end
